﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using LuaFramework;
using LuaInterface;

namespace LuaFramework {
 
	/// <summary>
	/// 用于2d碰撞
	/// </summary>
	public class LuaCollision2DComponent : LuaComponent {

		void OnCollisionEnter2D(Collision2D collision)
		{
			if (!string.IsNullOrEmpty(_name))
			{
				if (!LuaManager.IsInited || _table==null) return;

				LuaFunction func = _table.GetLuaFunction("OnCollisionEnter2D");
				if (func != null)
				{
					func.Call(_table,collision);
					func.Dispose();
					func = null;
				}
			}
		}

		void OnCollisionExit2D(Collision2D collision)
		{
			if (!string.IsNullOrEmpty(_name))
			{
				if (!LuaManager.IsInited || _table==null) return;

				LuaFunction func = _table.GetLuaFunction("OnCollisionExit2D");
				if (func != null)
				{
					func.Call(_table,collision);
					func.Dispose();
					func = null;
				}
			}
		}

		void OnCollisionStay2D(Collision2D collision)
		{
			if (!string.IsNullOrEmpty(_name))
			{
				if (!LuaManager.IsInited || _table==null) return;

				LuaFunction func = _table.GetLuaFunction("OnCollisionStay2D");
				if (func != null)
				{
					func.Call(_table,collision);
					func.Dispose();
					func = null;
				}
			}
		}

		void OnTriggerEnter2D(Collider2D collider)
		{
			if (!string.IsNullOrEmpty(_name))
			{
				if (!LuaManager.IsInited || _table==null) return;

				LuaFunction func = _table.GetLuaFunction("OnTriggerEnter2D");
				if (func != null)
				{
					func.Call(_table,collider);
					func.Dispose();
					func = null;
				}
			}
		}

		void OnTriggerStay2D(Collider2D collider)
		{
			if (!string.IsNullOrEmpty(_name))
			{
				if (!LuaManager.IsInited || _table==null) return;

				LuaFunction func = _table.GetLuaFunction("OnTriggerStay2D");
				if (func != null)
				{
					func.Call(_table,collider);
					func.Dispose();
					func = null;
				}
			}
		}

		void OnTriggerExit2D(Collider2D collider)
		{
			if (!string.IsNullOrEmpty(_name))
			{
				if (!LuaManager.IsInited || _table==null) return;

				LuaFunction func = _table.GetLuaFunction("OnTriggerExit2D");
				if (func != null)
				{
					func.Call(_table,collider);
					func.Dispose();
					func = null;
				}
			}
		}

		void OnJointBreak2D(Joint2D brokenJoint)
		{
			if (!string.IsNullOrEmpty(_name))
			{
				if (!LuaManager.IsInited || _table==null) return;

				LuaFunction func = _table.GetLuaFunction("OnJointBreak2D");
				if (func != null)
				{
					func.Call(_table,brokenJoint);
					func.Dispose();
					func = null;
				}
			}
		}
    }
}